home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: regmia@ix.netcom.com
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Passing functions as parameters... inconsistent behaviour
- Date: Sat, 24 Feb 1996 07:18:21 GMT
- Organization: Netcom
- Message-ID: <4gme0e$atu@cloner4.netcom.com>
- References: <4glbau$tge@inet.up.ac.za>
- NNTP-Posting-Host: ix-lv5-10.ix.netcom.com
- X-NETCOM-Date: Fri Feb 23 11:16:30 PM PST 1996
- X-Newsreader: Forte Free Agent 1.0.82
-
- In your code fragment you must declare what type of parameters are
- going to be sent to the function, if any parameters, for example:
-
- >void test(float (*passedfunc)(float)) {
- > passedfunc(1); /*see ------- */
- >}
-
- >float passed(float a){
- > return 1.0;
- >}
-
- >int main(void) {
- > test( passed );
- > return 0;
- >}
-
- See what I mean, I guarantee it will work for you each and every time.
- :)
-
-
- Rudolph Pienaar <rudolph@pangea.ee.up.ac.za> wrote:
-
- >Hello all -
-
- >I've noticed strange compiler behaviour when changing the *type* of data in the
- >parameter list of a passed function...
-
- >Consider this simple code fragment:
-
- >/***********************************/
- >void test(float (*passedfunc)()) {
- > passedfunc(1);
- >}
-
- >float passed(float a){
- > return 1.0;
- >}
-
- >int main(void) {
- > test( passed );
- > return 0;
- >}
- >/***********************************/
-
- >Reasonably straightforward - the function "passed" is sent on to another
- >function, "test". "test", in turn calls the function that was passed to it.
-
- >This little piece of meaningless code compiles without any hitches, yet when I
- >change the type of "a" in passed's parameter list to float, ie:
-
- > float passed(int a) ---> float passed(float a)
- > ^^^ ^^^^^
-
- >and recompile, I get the following warning:-
-
- >ptr.c: In function `main':
- >ptr.c:17: warning: passing arg 1 of `test' from incompatible pointer type
-
- >Of course, this is just a sample... the general rule seems to be that if a
- >function is passed to another, and if this passed function has any parameters
- >of its own other than *int* (and this includes user defined types), compilation
- >results in a similar warning.
-
- >I have received identical results with gcc / cc on the following platforms:
- >> An i486 running Linux (1.1.59)
- >> A RS6000 running AIX 3.2.4
- >> A SunSparc running SunOS 5.3
-
- >Although I haven't noticed any strange behaviour in running programs after this
- >warning, I have no idea why the compiler generates this message.
-
- >Any comments, explanations, suggestions, corrections will be much appreciated.
-
- >Thanks
- >Rudolph
-
- >________________________________________________________________________
- >e-mail: rudolph@pangea.ee.up.ac.za
- >In Real Life: Rudolph Pienaar
- >Organization: Electrical and Electronic Engineering
- > University of Pretoria
- > South Africa
- >________________________________________________________________________
-
-
-
-